package com.cdd.goods.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cdd.goods.mapper.GoodsShopMapper;
import com.cdd.goods.service.IGoodsShopService;
import com.common.entity.Goods;
import com.common.entity.GoodsShop;
import com.common.entity.Order;
import com.common.entity.OrderShop;
import com.common.entity.Shop;
import com.common.untils.CommonResult;
import com.common.vo.GoodsVo;
import com.common.vo.ShopVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lzl
 * @since 2022-09-01
 */
@Service
public class GoodsShopServiceImpl implements IGoodsShopService {
    @Autowired
    private GoodsShopMapper goodsShopMapper;
    @Override
    public Integer editGoodsState(Integer sid) {
        GoodsShop goodsShop = new GoodsShop();
        goodsShop.setState(1);
        QueryWrapper<GoodsShop> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("sid",sid);
        Integer row = goodsShopMapper.update(goodsShop, queryWrapper);
        return row;
    }

    @Override
    public Integer editGoodsState02(Integer sid) {
        GoodsShop goodsShop = new GoodsShop();
        goodsShop.setState(0);
        QueryWrapper<GoodsShop> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("sid",sid);
        Integer row = goodsShopMapper.update(goodsShop, queryWrapper);
        return row;
    }

    @Override
    public CommonResult selectshop(Integer currentPage,Integer pageSize,ShopVo shopVo ) {
        Page<ShopVo> page = new Page<>(currentPage,pageSize);
        QueryWrapper<ShopVo> wrapper=new QueryWrapper();
        wrapper.eq("s.is_deleted",0);
        if (StringUtils.hasText(shopVo.getGname())){
            wrapper.like("gs.gname",shopVo.getGname());
        }
        if (shopVo.getState()!=null){
            wrapper.eq("state",shopVo.getState());
        }
        Page<ShopVo> mapPage = goodsShopMapper.selectShopAll(page,wrapper);

        System.out.println(mapPage+"==================");

        return new CommonResult(2000,"查询成功",mapPage);
    }

    @Override
    public CommonResult gerShopGoodsEchar() {
       List<Shop> list =  goodsShopMapper.selectAllShop();

       List<Map> mapList = new ArrayList<>();
        for (Shop s : list) {
            QueryWrapper queryWrapper = new QueryWrapper();
            queryWrapper.eq("sid",s.getId());
            queryWrapper.eq("state",0);
            queryWrapper.eq("is_deleted",0);
            List<GoodsShop> list1 = goodsShopMapper.selectList(queryWrapper);
            Map map = new HashMap();
            map.put("name",s.getName());
            map.put("value",list1.size());
            mapList.add(map);
        }
        return new CommonResult(2000,"查询成功",mapList);
    }


}
